package weaver.interfaces.jjy.duss.action;

import com.weaver.general.BaseBean;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.jjy.duss.hr.ZFM_HR_BZ_ZGJG_CONFIRM;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2020-05-09
 * @Description: 主管架构调整推送SAP
 * @ModifyLog:
 **/

public class WeaZgjgtztsConfirmAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        weaver.general.BaseBean baseBean = new weaver.general.BaseBean();
        String requestid = requestInfo.getRequestid();
        baseBean.writeLog("请求ID" + requestid);
        baseBean.writeLog("调用WeaZgjgtztsConfirmAction");
        String tablename = requestInfo.getRequestManager().getBillTableName();//主表
        rs.executeQuery("select ZEHR_ZTWB,ZEHR_FSRQ from " + tablename + " where requestid=?", requestid);
        baseBean.writeLog("select ZEHR_ZTWB,ZEHR_FSRQ from " + tablename + " where requestid=" + requestid);
        rs.next();
        //主表字段
        String ZEHR_FSRQ = Util.null2String(rs.getString("ZEHR_FSRQ").replaceAll("-", ""));//发送日期
        Map<String,String> map = new HashMap<>();
        map.put("IV_DATUM",ZEHR_FSRQ);//日期
        map.put("IV_NUMID",requestid);//OA主键
        try {
            ZFM_HR_BZ_ZGJG_CONFIRM bz_zgjg_confirm = new ZFM_HR_BZ_ZGJG_CONFIRM();
            Map<String, String> resultMap = bz_zgjg_confirm.execute(map);
            String flag = Util.null2String(resultMap.get("flag"));
            String message = Util.null2String(resultMap.get("message"));
            baseBean.writeLog("SAP返回结果——flag:" + flag + ";message:" + message);
            if ("E".equalsIgnoreCase(flag)) {
                requestInfo.getRequestManager().setMessageid("111111");
                requestInfo.getRequestManager().setMessagecontent("SAP返回信息提示:"+message);
                return Action.FAILURE_AND_CONTINUE;
            }
            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            baseBean.writeLog("异常参考:" + e);
            requestInfo.getRequestManager().setMessageid("111111");
            requestInfo.getRequestManager().setMessagecontent(e.getMessage());
            return Action.FAILURE_AND_CONTINUE;
        }

    }
}
